/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.proxyobjects;

import java.util.Collections;
import java.util.Map;

import javax.swing.Icon;

import org.kommando.core.catalog.CatalogObject;
import org.kommando.core.util.Assert;

/**
 * @author Peter De Bruycker
 */
public class ProxyCatalogObject implements CatalogObject {

    private ProxyObject proxyObject;

    public ProxyCatalogObject(ProxyObject proxyObject) {
        Assert.argumentNotNull("proxyObject", proxyObject);

        this.proxyObject = proxyObject;
    }

    @Override
    public String getDescription() {
        return "Proxy Object";
    }

    @Override
    public Icon getIcon() {
        return proxyObject.getIcon();
    }

    @Override
    public String getName() {
        return proxyObject.getName();
    }

    @Override
    public String getId() {
        return "proxy:" + proxyObject.getClass().getName();
    }

    @Override
    public <T> T getExtension(Class<T> extensionType) {
        return extensionType.cast(proxyObject.getExtension(extensionType));
    }

    @Override
    public boolean hasExtension(Class<?> extensionType) {
        Assert.argumentNotNull("extensionType", extensionType);

        return extensionType.equals(proxyObject.getExtensionType());
    }

    @Override
    public Map<Class<?>, Object> getExtensions() {
        return Collections.<Class<?>, Object> singletonMap(proxyObject.getExtensionType(), proxyObject.getExtension(proxyObject.getExtensionType()));
    }

    @Override
    public <T> void setExtension(Class<T> extensionType, T extension) {
        // not supported
    }

}
